<?php  defined('C5_EXECUTE') or die(_("Access Denied."));?>
<?php   if (($this->controller->getTask() == 'update' || $this->controller->getTask() == 'edit' || $this->controller->getTask() == 'add' || $this->controller->getTask() == 'delete')) { ?>
	
	<?php   
	$df = Loader::helper('form/date_time');
	$miscFields=array();
	if (is_object($project)) { 
		$projectTitle = $project->getCollectionName();
		$projectDescription = $project->getCollectionDescription();
		$projectDate = $project->getCollectionDatePublic();
		$cParentID = $project->getCollectionParentID();
		$ctID = $project->getCollectionTypeID();
		// Value store on attribute
		$projectPrice = $project->getAttribute('projectestate_price');
		$projectWebsite = $project->getAttribute('projectestate_website');
		$cLocationID = $project->getAttribute('projectestate_location');
		$cTypeID = $project->getAttribute('projectestate_type');
		$cNumberOfRoom = $project->getAttribute('projectestate_numberofroom');
		$cLogoID = null;		
		if ($cLogoID = $project->getAttribute('projectestate_logo')) { 
			$cLogoID = File::getByID($cLogoID);
		}
		
		$projectBody = '';
		$eb = $project->getBlocks('Main');
		if (is_object($eb[0])) {
			$projectBody = $eb[0]->getInstance()->getContent();
		}
		if ($this->controller->getTask() != 'delete'){
			$task = 'update';
			$buttonText = t('Update Entry');
			$title = t('Update');
		}else{
			$task = 'remove';
			$buttonText = t('Delete Entry');
			$title = t('Delete');
			$miscFields=array('disabled'=>'true');
		}
	} else {
		$task = 'add';
		$title = t('Add');
		$buttonText = t('Add Project Entry');
	}
	$includeAssetLibrary = true;
	$assetLibraryPassThru = array(
		'type' => 'image'
	);
	$al = Loader::helper('concrete/asset_library');
	?>
	<div style="width: 760px">
	
	<h1><span><?php  echo t('Project')?></span></h1>
	<div class="ccm-dashboard-inner">
	
	<h2><span><?php  echo $title?> Project Entry</span></h2>
	
	<form method="post" action="<?php  echo $this->action($task)?>" id="project-form">
	<?php   if ($this->controller->getTask() != 'add') { ?>
		<?php  echo $form->hidden('projectID', $project->getCollectionID())?>
	<?php   } ?>
	
	<strong><?php  echo $form->label('projectTitle', t('Title'))?></strong>
	<div><?php  echo $form->text('projectTitle', $projectTitle, array_merge(array('style' => 'width: 730px'),$miscFields))?></div>
	<br/>
	<strong><?php  echo $form->label('projectDescription', t('Summary'))?></strong>
	<div><?php  echo $form->textarea('projectDescription', $projectDescription, array_merge(array('style' => 'width: 730px; height: 100px'),$miscFields))?></div>
	<br/>
	<strong><?php  echo $form->label('projectLogo', t('Logo'))?></strong>
	<div>
		<?php echo $al->image('project-image', 'projectLogo', t('Choose Image Logo'), $cLogoID);?>
	</div>
	<br/>
	<strong><?php  echo $form->label('projectType', t('Type'))?></strong>
	<div>
		<?php if (count($types) == 0): ?>
			<?php  echo t('No project type defined. Please create a project type.')?>
		<?php else:?>
			<?php  echo $form->select('projectType', $types, $cTypeID)?>
		<?php endif;?>
	</div>
	<br/>
	<strong><?php  echo $form->label('projectLocation', t('Location'))?></strong>
	<div>
		<?php if (count($types) == 0): ?>
			<?php  echo t('No project type defined. Please create a project type.')?>
		<?php else:?>
			<?php  echo $form->select('projectLocation', $locations, $cLocationID)?>
		<?php endif;?>
	</div>
	<br/>
	<strong><?php  echo $form->label('projectNumberOfRoom', t('Number Of Room'))?></strong>
	<div>
		<?php if (count($types) == 0): ?>
			<?php  echo t('No project number of room defined. Please create a project Number Of Room.')?>
		<?php else:?>
			<?php  echo $form->select('projectNumberOfRoom', $numberofrooms, $cNumberOfRoom)?>
		<?php endif;?>
	</div>
	<br/>
	<strong><?php  echo $form->label('projectPrice', t('Price'))?></strong>
	<div><?php  echo $form->text('projectPrice', $projectPrice, array_merge(array('style' => 'width: 300px'),$miscFields))?></div>
	<br/>
	<strong><?php  echo $form->label('projectWebsite', t('Website'))?></strong>
	<div><?php  echo $form->text('projectWebsite', $projectWebsite, array_merge(array('style' => 'width: 300px'),$miscFields))?></div>
	<br/>	
	<?php  if ($task!='remove'){ ?>
	<strong><?php  echo $form->label('cParentID', t('Section'))?></strong>
	<?php   if (count($sections) == 0) { ?>
		<div><?php  echo t('No sections defined. Please create a page with the attribute "simpleproject_entry" set to true.')?></div>
	<?php   } else { ?>
		<div><?php  echo $form->select('cParentID', $sections, $cParentID)?></div>
	<?php   } ?>
<br/>
	
	<strong><?php  echo $form->label('ctID', t('Page Type'))?></strong>
	<div><?php  echo $form->select('ctID', $pageTypes, $ctID)?></div>
	<br/>
	<strong><?php  echo $form->label('lang', t('Language'))?></strong>
	<?php if(is_object($project)):?>
		<div><?php  echo $form->radio('lang', 'en', !(bool)$project->getAttribute('Vietnamese_menu')) . $form->label('', t(' English')) . $form->radio('lang', 'vn', (bool)$project->getAttribute('Vietnamese_menu')) ." ". $form->label('', t(' Vietnamese')) ;?></div>
	<?php else :?>
		<div><?php  echo $form->radio('lang', 'en', true) . $form->label('', t(' English')) . $form->radio('lang', 'vn') ." ". $form->label('', t(' Vietnamese')) ;?></div>
	<?php endif;?>
	<br/>
	<strong><?php  echo $form->label('projectDate', t('Date/Time'))?></strong>
	<div><?php  echo $df->datetime('projectDate', $projectDate)?></div>
	<br/>
	<strong><?php  echo t('Full text')?></strong>
	<?php   Loader::element('editor_init'); ?>
	<?php   Loader::element('editor_config'); ?>
	<?php   Loader::element('editor_controls', array('mode'=>'full')); ?>
	// <?php  echo $form->textarea('projectBody', $projectBody, array('style' => 'width: 100%; height: 150px', 'class' => 'ccm-advanced-editor'))?>
	
	<br/>
	<?php  } ?>
	<?php  
	$ih = Loader::helper('concrete/interface');
	print $ih->button(t('Cancel'), $this->url('/dashboard/easy_project/'), 'left');
	print $ih->submit($buttonText, 'project-form');
	?>
	<div class="ccm-spacer">&nbsp;</div>
	
	</form>
	
	</div>
	</div>
	
	<?php   } else { ?>
	
		<h1><span><?php  echo t('Project')?></span></h1>
		<div class="ccm-dashboard-inner">
		<h2><?php  echo t('Add Project')?></h2>
		<a href="<?php  echo $this->action('add')?>"><?php  echo t('Click here to add a new Project Entry &gt;')?></a>
		<Br/><br/>
		
		<h2><?php  echo t('View/Search Project')?></h2>
	
		<form method="get" action="<?php  echo $this->action('view')?>">
			<?php  
			$sections[0] = '** All';
			asort($sections);
			?>
		
			<strong><?php  echo $form->label('cParentID', t('Section'))?></strong>
			<div><?php  echo $form->select('cParentID', $sections, $cParentID)?></div>
			<br/>
			<strong><?php  echo $form->label('lang', t('Language'))?></strong>
			<div><?php  echo $form->radio('lang', 'en', true) . $form->label('', t(' English')) . $form->radio('lang', 'vn', false) ." ". $form->label('', t(' Vietnamese')) ;?></div>
			<br/>
			<div><?php  echo $form->submit('submit', 'Search')?></div>
		</form>
		<br/>
		<?php  
		$nh = Loader::helper('navigation');
		if ($projectList->getTotal() > 0) { 
			$projectList->displaySummary();
			?>
			
		<table border="0" class="ccm-results-list" cellspacing="0" cellpadding="0">
			<tr>
				<th class="<?php  echo $projectList->getSearchResultsClass('cvName')?>"><a href="<?php  echo $projectList->getSortByURL('cvName', 'asc')?>"><?php  echo t('Name')?></a></th>
				<th class="<?php  echo $projectList->getSearchResultsClass('cType')?>"><a href="<?php  echo $projectList->getSortByURL('cType', 'asc')?>"><?php  echo t('Type')?></a></th>
				<th class="<?php  echo $projectList->getSearchResultsClass('cLocation')?>"><a href="<?php  echo $projectList->getSortByURL('cLocation', 'asc')?>"><?php  echo t('Location')?></a></th>
				<th class="<?php  echo $projectList->getSearchResultsClass('cNumberOfRoom')?>"><a href="<?php  echo $projectList->getSortByURL('cNumberOfRoom', 'asc')?>"><?php  echo t('Number Of Room')?></a></th>
				<th class="<?php  echo $projectList->getSearchResultsClass('cDateAdded')?>"><a href="<?php  echo $projectList->getSortByURL('cDateAdded', 'asc')?>"><?php  echo t('Date Added')?></a></th>
				<th class="<?php  echo $projectList->getSearchResultsClass('cvDatePublic')?>"><a href="<?php  echo $projectList->getSortByURL('cvDatePublic', 'asc')?>"><?php  echo t('Public Date')?></a></th>
				<th><?php  echo t('Page Owner')?></th>
				<th>&nbsp;</th>
				<th>&nbsp;</th>
			</tr>
			<?php 
			foreach($projectResults as $cobj) { ?>
			<tr>
				<td><a href="<?php  echo $nh->getLinkToCollection($cobj)?>"><?php  echo $cobj->getCollectionName()?></a></td>
				<td><?php  echo $types[$cobj->getCollectionAttributeValue('projectestate_type')];?></td>
				<td><?php  echo $locations[$cobj->getCollectionAttributeValue('projectestate_location')];?></td>
				<td><?php  echo $numberofrooms[$cobj->getCollectionAttributeValue('projectestate_numberofroom')];?></td>
				<td><?php  echo $cobj->getCollectionDateAdded()?></td>
				<td><?php  echo $cobj->getCollectionDatePublic()?></td>
				<td>
					<?php   
					$user = UserInfo::getByID($cobj->getCollectionUserID());
					print $user->getUserName();
					?>
				</td>
				<td><A href="<?php  echo $this->url('/dashboard/project_estate', 'edit', $cobj->getCollectionID())?>"><?php  echo t('Edit')?></a></td>
				<td><A href="<?php  echo $this->url('/dashboard/project_estate', 'delete', $cobj->getCollectionID())?>"><?php  echo t('Delete')?></a></td>
			</tr>
			<?php   } ?>
			
			</table>
			<br/>
			<?php  
			$projectList->displayPaging();
		} else {
			print t('No Project entries found.');
		}
		?>
		</div>
		
	<?php   }?>
